package cn.tedu.sp04orderservice.controller;

import cn.tedu.entity.Item;
import cn.tedu.entity.Order;
import cn.tedu.entity.User;
import cn.tedu.service.OrderService;
import cn.tedu.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String order){
        Order order1 = orderService.getOrder(order);
        return JsonResult.build().code(200).data(order1);
    }
    @GetMapping("/add")
    public JsonResult<?> addOrder(Order order){
        Order order1 = new Order();
        order1.setId("466534564");
        order1.setItems(Arrays.asList(new Item[]{
                new Item(1,"焦旭斌贴身超薄不侧漏1",6),
                new Item(2,"焦旭斌贴身超薄不侧漏2",6),
                new Item(3,"焦旭斌贴身超薄不侧漏3",6),
                new Item(4,"焦旭斌贴身超薄不侧漏4",6),
                new Item(5,"焦旭斌贴身超薄不侧漏5",6)
        }));
        order1.setUser(new User(8,null,null));
        orderService.addOrder(order1);
        return JsonResult.build().code(200).msg("订单添加成功");
    }
    @GetMapping("/favicon.ico")
    public void ico(){

    }
}
